package com.laviedesfons.jhmtasc.types.internals;

import com.laviedesfons.jhmtasc.annotations.binding.MType;
import com.laviedesfons.jhmtasc.types.interfaces.InternalType;
import fr.x9c.cadmium.kernel.Block;
import fr.x9c.cadmium.kernel.Value;

/**
 *
 * @author Romano
 */
@MType(camlType="int")
public final class PFloat implements InternalType {

    private double value;

    public PFloat() { }
    public PFloat(double v){
        this.value = v;
    }

    @Override
    public PFloat fromValue(Value v) {
        this.value = v.asBlock().asDouble();
        return this;
    }

    @Override
    public Value toValue() {
        return Value.createFromBlock(Block.createDouble(value));
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PFloat other = (PFloat) obj;
        if (Double.doubleToLongBits(this.value) != Double.doubleToLongBits(other.value)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (int) (Double.doubleToLongBits(this.value) ^ (Double.doubleToLongBits(this.value) >>> 32));
        return hash;
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }
}
